<?php
/**
 * 功能：json测试数据(mysql)
 * 说明：
 * 创建日期：
 * 更新日期：
 * 作者：Mirze
 * 补充说明： 
 * 
 */
include('ThePage.class.php');

$db = Factory::getDB('zy_week_active');

//--- 查询日期 (周)---
//-------------------

$_search = ('true' == $_POST['_search']) ? true : false; //是否搜索
$oper = isset($_POST['oper']) ? trim($_POST['oper']) : ''; //操作来源：add/edit/del

$sidx = isset($_POST['sidx']) ? trim($_POST['sidx']) : ''; //主键
$sord= ('desc' == $_POST['sord']) ? 'desc' : 'asc'; //排序
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 5;  //取每页记录条数

$where = '1';
$col = $sidx;

/** 搜索 **/
if($_search) {
	$oper = 'search';
}

switch($oper) {
	case 'search':
		$searchField = isset($_POST['searchField']) ? trim($_POST['searchField']) : ''; //字段
		$searchString = isset($_POST['searchString']) ? trim($_POST['searchString']) : ''; //值
		$searchOper = isset($_POST['searchOper']) ? trim($_POST['searchOper']) : 'eq'; //查询条件：
		if('' != $searchField) {
			$where = "{$searchField} = '{$searchString}'";
		}

	    break;
	case 'add':
		$val['team_name'] = isset($_POST['team_name']) ? trim($_POST['team_name']) : '';
		$val['well_name'] = isset($_POST['well_name']) ? trim($_POST['well_name']) : '';
		$val['work_type'] = isset($_POST['work_type']) ? trim($_POST['work_type']) : '';
		$val['well_ptd'] = isset($_POST['well_ptd']) ? trim($_POST['well_ptd']) : '';
		$val['ctd'] = isset($_POST['ctd']) ? trim($_POST['ctd']) : '';
		$val['work_plan'] = isset($_POST['work_plan']) ? trim($_POST['work_plan']) : '';
		$val['next_well'] = isset($_POST['next_well']) ? trim($_POST['next_well']) : '';
		$val['active_info'] = isset($_POST['active_info']) ? trim($_POST['active_info']) : '';

		/* 隐藏数据 */
		$val['create_time'] = date('Y-m-d');
		//$val['project'] = isset($_POST['project']) ? trim($_POST['project']) : '';
		$val['project'] = '测试项目';
		//$val['department'] = get_user_dev($_POST['create_user']);

		$res = $db->insert_zy_week_active($val);
		if(empty($res)) {
			echo "<script>alert('添加失败');</script>";
		}
	    break;
	case 'edit':
	
	    break;
	case 'del':
		$id = isset($_POST['id']) ? intval($_POST['id']) : 0; 
		$where = "active_id = '{$id}'";
		$res = $db->delete_zy_week_active($where);
	    break;
	default:
		
		break;
}

if('asc' == $sord) {$db->setOrderBy();}
$datas = $db->getAll($where, $col);
$list_data = is_array($datas) ? $datas : array();

$num = count($list_data); //总记录条数
$total = ($rows < 1) ? 0 : ceil($num/$rows); //总页数

//json
$json_arr['page'] = 1; //json中代表当前页码的数据
$json_arr['total'] = $total;
$json_arr['records'] = $num; 
$json_arr['list_data'] = $list_data; //数据

echo json_encode($json_arr);

?>